﻿namespace com.stifel.BranchMgmtDao
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    public partial class StifelBranchInfo
    {
        #region Fields

        string _AddressAsHtml;
        List<string> _BroadCastIp;
        string _BroadCastIpAsHtml;

        #endregion Fields

        #region Properties

        /// <summary>
        /// Gets the branch address formatted as html.
        /// </summary>
        public string AddressAsHtml
        {
            get
            {
                if ( string.IsNullOrEmpty( _AddressAsHtml ) )
                {
                    StringBuilder sb = new StringBuilder( );
                    if ( !string.IsNullOrEmpty( Title ) )
                        sb.AppendFormat( "{0}\t", Title );
                    if ( !string.IsNullOrEmpty( BranchStreetAddress ) )
                        sb.AppendFormat( "&nbsp;\t{0}\t", BranchStreetAddress );
                    if ( !string.IsNullOrEmpty( BranchSuiteAddress ) )
                        sb.AppendFormat( "{0}\t", BranchSuiteAddress );
                    if ( !string.IsNullOrEmpty( BranchCity ) )
                        sb.AppendFormat( "{0}, ", BranchCity );
                    if ( !string.IsNullOrEmpty( USStatesLookupusr_us_value ) )
                        sb.AppendFormat( "{0}, ", USStatesLookupusr_us_value );
                    if ( !string.IsNullOrEmpty( BranchZipcode ) )
                        sb.AppendFormat( "{0}\t",BranchZipcode );
                    if ( !string.IsNullOrEmpty( TimeZoneLookupusr_tz_value ) )
                        sb.AppendFormat( "&nbsp;\t{0}\t", TimeZoneLookupusr_tz_value );
                    if ( !string.IsNullOrEmpty( BranchTypeTitle ) )
                        sb.AppendFormat( "&nbsp;\t{0}\t", BranchTypeTitle );
                    _AddressAsHtml = sb.ToString( ).Trim( ).Replace( "\t", "<br />" );
                    sb = null;
                }
                return _AddressAsHtml;
            }
        }

        public List<string> BroadCastIp
        {
            get
            {
                if ( _BroadCastIp == null )
                    _BroadCastIp = new List<string>( );
                if ( !string.IsNullOrEmpty( BroadcastIP ) )
                {
                    _BroadCastIp = BroadcastIP.Split( new string[ ] { ";" }, StringSplitOptions.RemoveEmptyEntries ).ToList( );
                    _BroadCastIp.ForEach( a => a.Trim( ) );
                    _BroadCastIp.Sort( );
                }
                return ( _BroadCastIp );
            }
        }

        public string BroadCastIPAsHtml
        {
            get
            {
                if ( string.IsNullOrEmpty( _BroadCastIpAsHtml ) )
                {
                    StringBuilder sb = new StringBuilder( );
                    BroadCastIp.ForEach( a => sb.AppendFormat( "{0}\t", a ) );
                    _BroadCastIpAsHtml = sb.ToString( ).TrimEnd( '\t' ).Replace( "\t", "<br />" );
                    sb = null;
                }
                return _BroadCastIpAsHtml;
            }
        }

        #endregion Properties
    }
}